package com.sky.controller.user;

import com.sky.dto.UserLoginDTO;
import com.sky.pojo.Category;
import com.sky.pojo.Dish;
import com.sky.pojo.Setmeal;
import com.sky.result.Result;
import com.sky.service.user.UserService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.UserLoginVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:篍
 * @Date: 2025/08/25 14:35
 * @Description:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户登录
     * @param userLoginDTO
     * @return
     */
    @PostMapping("/user/login")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
        UserLoginVO userLoginVO = userService.login(userLoginDTO);
        return Result.success(userLoginVO);
    }

    @GetMapping("/category/list")
    public Result<List<Category>> listCategory() {
        List<Category> list = userService.listCategory();
        return Result.success(list);
    }

    /**
     * 获取用户端菜品列表
     * @return
     */
    @GetMapping("/dish/list")
    public Result<List<DishVO>> listDish(Long categoryId) {
        List<DishVO> list = userService.listDishVo(categoryId);
        return Result.success(list);
    }

    /**
     * 获取用户端套餐列表
     * @return
     */
    @GetMapping("/setmeal/list")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> listSetMeal(Long categoryId) {
        List<Setmeal> list = userService.listSetmeal(categoryId);
        return Result.success(list);
    }

    /**
     * 获取套餐内包含的菜品数据
     * @param setmealId
     * @return
     */
    @GetMapping("/setmeal/dish/{setmealId}")
    public Result<List<DishItemVO>> listSetmealDish(@PathVariable Long setmealId) {
        List<DishItemVO> list = userService.listDishItemVo(setmealId);
        return Result.success(list);
    }
}
